<%@page import="com.feib.stms.util.UserUtil"%>
<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.stms.action.BaseUploadActionBean"%>

<%
// 欄位排序處理
BaseUploadActionBean actionBean = (BaseUploadActionBean) request.getAttribute("actionBean");
actionBean.setErrorNavigator();
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
        
    <script type="text/javascript">
    <!-- 
    $(document).ready(function() {
    
   	$('#doQueryBtn').click(function() {
   		$("#hidden\\.doQueryBtn").trigger('click');	
	});
    	
<c:if test="${null != actionBean.queryErrorResult && not empty actionBean.queryErrorResult.paginatedList}">
				
		$("[id^='a-sortHeader-']").click(function() {
			var sortField = this.id.substring(13);
			$('#hidden\\.queryErrorResult\\.sortCriterion').val(sortField);
			
			var clazz = $(this).attr('class');
			if (null == clazz || 0 == clazz.length)
				$('#hidden\\.queryErrorResult\\.sortDirection').val('1');
			else if ('sortAsc' == clazz)
				$('#hidden\\.queryErrorResult\\.sortDirection').val('1');
			else
				$('#hidden\\.queryErrorResult\\.sortDirection').val('2');
				
			$('#hidden\\.queryErrorResult\\.pageNumber').val('1');
				
			$("#hidden\\.doViewUploadErrorBtn").trigger('click');
			
		});
		
		$("[id^='firstPageBtn']").click(function() {
			$('#hidden\\.queryErrorResult\\.pageNumber').val('1');
			$("#hidden\\.doViewUploadErrorBtn").trigger('click');
		});
		
		$("[id^='prePageBtn']").click(function() {
			$('#hidden\\.queryErrorResult\\.pageNumber').val('<c:out value="${prePageNumber}"/>');
			$("#hidden\\.doViewUploadErrorBtn").trigger('click');
		});
		
		$("[id^='nextPageBtn']").click(function() {
			$('#hidden\\.queryErrorResult\\.pageNumber').val('<c:out value="${nextPageNumber}"/>');
			$("#hidden\\.doViewUploadErrorBtn").trigger('click');
		});
		
		$("[id^='lastPageBtn']").click(function() {
			$('#hidden\\.queryErrorResult\\.pageNumber').val('<c:out value="${lastPageNumber}"/>');
			$("#hidden\\.doViewUploadErrorBtn").trigger('click');
		});
		
		$("[id^='currentPageText']").change(function() {
			var value = this.value;
			if (value != ''){
				value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
				var intRegex = /^\d+$/;
				if(!intRegex.test(value)) {
					showErrorMessageDialog('頁數必須是整數');
					return ;
				}
				
				value = parseInt(value, 10);
				
				if (value < 1){
					showErrorMessageDialog('頁數必須是大於1');
					return ;
				}
				else if (value > <c:out value='${lastPageNumber}'/>){
					showErrorMessageDialog('頁數必須是小於總頁數 (<c:out value="${lastPageNumber}"/>)');
					return ;
				}
				else if (value != <c:out value='${currentPageNumber}'/>){
					doQueryAction();
					$('#hidden\\.queryErrorResult\\.pageNumber').val(value);
					$("#hidden\\.doViewUploadErrorBtn").trigger('click');
				}
				
			}
			else{
				showErrorMessageDialog('頁數不可為空白)');
				return ;
			}
		});
</c:if>
<c:if test="${null == actionBean.queryErrorResult || empty actionBean.queryErrorResult.paginatedList}">
		showMessageDialog('查無資料！');
</c:if>
                  
    }); 
    
    //-->
    </script>
</head>
<body>
	
	<div id="smallQueryForm"></div>
	
	<div id="queryForm"></div>
	
	<div id="listForm">
	
		<div id="paginationBar" style=" margin: 0 auto;">
			<input type="button" id="firstPageBtn" class="formBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			<input type="button" id="prePageBtn" class="formBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			第 <input type="text" id="currentPageText" class="formBtn" value="${currentPageNumber }" size="3" maxlength="4" /> / ${lastPageNumber} 頁
			<input type="button" id="nextPageBtn" class="formBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
			<input type="button" id="lastPageBtn" class="formBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
		</div>
		
		
		<table>
			<thead>
			<tr>
				<td colspan="<%=UserUtil.isBankGroup()? "5": "4" %>" class="listHeader">上傳檔案錯誤原因</td>
			</tr>
			<tr>
				<th></th>
				<th><a id='a-sortHeader-lineNumber' href='javascript:void(0);' class="<c:out value='${lineNumberSortedClass }'/>">錯誤行數<c:out value='${lineNumberSortedSpan }' escapeXml="false"/></a></th>
				<th><a id='a-sortHeader-columnName' href='javascript:void(0);' class="<c:out value='${columnNameSortedClass }'/>">欄位名稱<c:out value='${columnNameSortedSpan }' escapeXml="false"/></a></th>
				<th><a id='a-sortHeader-errorMessage' href='javascript:void(0);' class="<c:out value='${errorMessageSortedClass }'/>">錯誤原因<c:out value='${errorMessageSortedSpan }' escapeXml="false"/></a></th>
				<%if (UserUtil.isBankGroup()){ %>				
				<th><a id='a-sortHeader-exceptionMessage' href='javascript:void(0);' class="<c:out value='${exceptionMessageSortedClass }'/>">系統錯誤<c:out value='${exceptionMessageSortedSpan }' escapeXml="false"/></a></th>
				<%} %>
			</tr>
			</thead>
			<tbody>
			<c:forEach items="${actionBean.queryErrorResult.paginatedList}" var="viewObj" varStatus="rowstat">
			<tr>
				<td align="right"><c:out value="${ rowstat.index + 1}"/></td>
				<td align="right"><fmt:formatNumber value="${viewObj.lineNumber}" pattern="##,###" /></td>
				<td><c:out value="${ viewObj.columnName}"/></td>
				<td><c:out value="${ viewObj.errorMessage}"/></td>
				<%if (UserUtil.isBankGroup()){ %>	
				<td><c:out value="${ viewObj.exceptionMessage}"/></td>
				<%} %>
			</tr>
			</c:forEach>
			</tbody>
			<tfoot>
			<tr>
				<td colspan="<%=UserUtil.isBankGroup()? "5": "4" %>" class="listFunction"><input type="button" id="doQueryBtn" value="確定" name="doQueryBtn" class="formBtn"/></td>
			</tr>
			</tfoot>
		</table>
	</div>   


<div style="display: none;">
<stripes:form id="hidden.queryTempUploadFileFrom" beanclass="<%=actionBean.getClass().getName() %>" method="post" onsubmit="javascript: waitingDialog({});">
	<stripes:hidden id="hidden.queryErrorResult.pageNumber" name="queryErrorResult.pageNumber" />
	<stripes:hidden id="hidden.queryErrorResult.sortCriterion" name="queryErrorResult.sortCriterion" />
	<stripes:hidden id="hidden.queryErrorResult.sortDirection" name="queryErrorResult.sortDirection" />
	
	<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
	<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
	<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />
	<stripes:hidden id="hidden.tempUploadFilePk" name="tempUploadFilePk" />
	<stripes:submit id="hidden.doQueryBtn" name="doQuery" value="查詢" class="formBtn"/>
	<stripes:submit id="hidden.doDeleteTempUploadFileBtn" name="doDeleteTempUploadFile" value="刪除" class="formBtn"/>
	<stripes:submit id="hidden.doViewUploadErrorBtn" name="doViewUploadError" value="檢視錯誤" class="formBtn"/>
	<stripes:errors></stripes:errors>
</stripes:form>
</div>

</body>
</html>
